Formatting Definitions

We go through a fair amount of effort to format a file definition. I've derived most of the LATEX commands experimentally; it's quite likely that an expert could do a better job. The LATEX for the previous macro definition should look like this (perhaps modulo the scrap references):

\begin{flushleft} \small
\begin{minipage}{\linewidth} \label{scrap37}
$\langle$Interpret at-sequence {\footnotesize 18}$\rangle\equiv$
\vspace{-1ex}
\begin{list}{}{} \item
\mbox{}\verb@@{@@\\
\mbox{}\verb@@  int big_definition = FALSE;@@\\
\mbox{}\verb@@  c = source_get();@@\\
\mbox{}\verb@@  switch (c) {@@\\
\mbox{}\verb@@    case 'O': big_definition = TRUE;@@\\
\mbox{}\verb@@    case 'o': @@$\langle$Write output file definition {\footnotesize 19a}$\rangle$\verb@@@@\\
&vellip#vdots;
\mbox{}\verb@@    case '@@{\tt @@}\verb@@': putc(c, tex_file);@@\\
\mbox{}\verb@@    default:  c = source_get();@@\\
\mbox{}\verb@@              break;@@\\
\mbox{}\verb@@  }@@\\
\mbox{}\verb@@}@@$\Diamond$
\end{list}
\vspace{-1ex}
\footnotesize\addtolength{\baselineskip}{-1ex}
\begin{list}{}{\setlength{\itemsep}{-\parsep}\setlength{\itemindent}{-\leftmargin}}
\item Macro referenced in scrap 17b.
\end{list}
\end{minipage}\\[4ex]
\end{flushleft}

The flushleft environment is used to avoid LATEX warnings about underful lines. The minipage environment is used to avoid page breaks in the middle of scraps. The verb command allows arbitrary characters to be printed (however, note the special handling of the @@ case in the switch statement).

Macro and file definitions are formatted nearly identically. I've factored the common parts out into separate scraps.

@d Write output file definition @ Name *name = collect_file_name(); @<Begin the scrap environment@> fprintf(tex_file, "
verb@@¨write_single_scrap_ref(tex_file, scraps++); fputs("
equiv", tex_file); @<Fill in the middle of the scrap environment@> @<Write file defs@> @<Finish the scrap environment@> @

I don't format a macro name at all specially, figuring the programmer might want to use italics or bold face in the midst of the name.

@d Write macro definition @ Name *name = collect_macro_name(); @<Begin the scrap environment@> fprintf(tex_file, "
langlewrite_single_scrap_ref(tex_file, scraps++); fputs("
rangle
equiv", tex_file); @<Fill in the middle of the scrap environment@> @<Write macro defs@> @<Write macro refs@> @<Finish the scrap environment@> @

@d Begin the scrap environment @ fputs("
beginflushleft
small", tex_file); if (!big_definition) fputs("
beginminipage
linewidth", tex_file); fprintf(tex_file, "
labelscrap@

The interesting things here are the $\Diamond$ inserted at the end of each scrap and the various spacing commands. The diamond helps to clearly indicate the end of a scrap. The spacing commands were derived empirically; they may be adjusted to taste.

@d Fill in the middle of the scrap environment @ fputs("
vspace-1ex
beginlist
item", tex_file); copy_scrap(tex_file); fputs("
Diamond
endlist", tex_file); @

We've got one last spacing command, controlling the amount of white space after a scrap.

Note also the whitespace eater. I use it to remove any blank lines that appear after a scrap in the source file. This way, text following a scrap will not be indented. Again, this is a matter of personal taste.

@d Finish the scrap environment @ if (!big_definition) fputs("
endminipage





", tex_file); fputs("
endflushleft", tex_file); do c = source_get(); while (isspace(c)); @



Subsections